<ion-view view-title="增加部门" show-tabs>

    <ion-content class="wrap-light2">
    <form name="addDeptForm" ng-submit="add()">
      <ion-list>

         <label class="item item-select">
          <span class="input-label">部门类型</span>
          <select ng-model="newDept.type" ng-change="typeSelect()" required>
            <option value="">-- 请选择 --</option>
            <option ng-repeat="option in dept_options.value_set" value="{{option.name}}">{{option.name}}</option>
          </select>
        </label>

         <label class="item item-select" ng-if="parentDepts.length || newDept.parent_id">
          <span class="input-label">上级部门</span>
          <select ng-model="newDept.parent_id">

            <option ng-repeat="parent_dept in parentDepts" value="{{parent_dept._id || newDept.parent_id}}" ng-selected="(parent_dept._id==newDept.parent_id) || ($index==0)">{{parent_dept.name}}</option>
          </select>
        </label>


        <label class="item item-input">
          <span class="input-label">部门名称</span>
          <input type="text" name="name" maxlength="20" required ng-model="newDept.name">
          <span class="ion-minus-circled" ng-show="addDeptForm.name.$dirty && addDeptForm.name.$invalid "></span>
        </label>

        <label class="item item-input" ng-if="newDept.type!='店内柜组'">
          <span class="input-label">部门电话</span>
          <input type="text" name="tel" maxlength="20" ng-model="newDept.tel" placeholder="部门联系电话">
        </label>

        <label class="item item-divider margin-top-large">
          部门地址
        </label>
        <ion-toggle ng-model="isUseParentAddr" toggle-class="toggle-royal"><span>与上级部门相同</span></ion-toggle>

        <div ng-if="!isUseParentAddr && newDept.type!='店内柜组'">
          <label class="item item-input">
            <span class="input-label">部门地址</span>
            <input type="text" name="province" maxlength="10" placeholder="省" ng-model="newDept.address.province"/>
            <input type="text" name="city" maxlength="10" placeholder="市" ng-model="newDept.address.city"/>
            <input type="text" name="region" maxlength="10" placeholder="区" ng-model="newDept.address.region"/>
          </label>
          <label class="item item-input" ng-if="newDept.type!='店内柜组'">
            <span class="list-label"> </span>
            <input type="text" name="street" maxlength="50" placeholder="详细地址" ng-model="newDept.address.street"/>
          </label>
        </div>


        <button class="button button-block button-royal" type="submit">确认添加</button>

      </ion-list>
      </form>
    </ion-content>
</ion-view>
